﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }



        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void calculate_Click(object sender, EventArgs e)
        {
            double n1 = 0, n2 = 0;
            try
            {
                n1 = Double.Parse(sum1.Text);
                n2 = Double.Parse(sum2.Text);
                switch (option.Text)
                {
                    case "+":
                        sum.Text = "结果：" + (n1 + n2);
                        break;
                    case "-":
                        sum.Text = "结果：" + (n1 - n2);
                        break;
                    case "*":
                        sum.Text = "结果：" + (n1 * n2);
                        break;
                    case "/":
                        sum.Text = "结果：" + (n1 / n2);
                        break;
                    default:
                        MessageBox.Show("运算符呢？");
                        break;

                }
            }
            catch(FormatException)
            {
                MessageBox.Show("输入错误!","错误",MessageBoxButtons.OK, MessageBoxIcon.Error);
               // return;
            }
            catch(OverflowException)
            {
                MessageBox.Show("溢出!");
               // return;
            }
//            catch (DivideByZeroException)
//            {
//               MessageBox.Show("除0错误！");
//               return;
//            }

        }


    }
}
